package com.jzo2o.foundations.controller.operation;

import com.jzo2o.common.model.PageResult;
import com.jzo2o.foundations.model.domain.Serve;
import com.jzo2o.foundations.model.dto.request.ServePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.service.IServeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

/**
 * 区域服务管理相关的代码
 */

@RestController("operationServeController") // 为了区分bean 名称
@RequestMapping("/operation/serve")
@Api(tags = "运营端 - 区域服务管理相关接口")
public class ServeController {
    @Resource
    private IServeService serveService;

    // GET/foundations/operation/serve/page
    @GetMapping("/page")
    @ApiOperation("区域服务分页查询")
    public PageResult<ServeResDTO> Page(ServePageQueryReqDTO servePageQueryReqDTO){
        PageResult<ServeResDTO> page = serveService.page(servePageQueryReqDTO);
        return page;
    }

    // POST/foundations/operation/serve/batch
    @PostMapping("/batch")
    @ApiOperation("区域服务批量新增")
    public void add(@RequestBody List<ServeUpsertReqDTO> serveUpsertReqDTOS){
        serveService.batchAdd(serveUpsertReqDTOS);
    }

    // DELETE/foundations/operation/serve/{id}
    @DeleteMapping("/{id}")
    @ApiOperation("区域服务删除")
    public void delete(@PathVariable("id")Long id){
        serveService.deleteById(id);
    }
    //PUT/foundations/operation/serve/{id}
    @PutMapping("/{id}")
    @ApiOperation("区域服务价格修改")
    public void update(@PathVariable("id") Long id,
                       @RequestParam("price")BigDecimal price){
        serveService.update(id, price);
    }

    //PUT/foundations/operation/serve/onSale/{id}
    @PutMapping("/onSale/{id}")
    @ApiOperation("区域服务上架")
    public void onSale(@PathVariable("id")Long id){
        serveService.onSale(id);
    }

    // PUT/foundations/operation/serve/offSale/{id}
    @PutMapping("/offSale/{id}")
    @ApiOperation("区域服务下架")
    public void offSale(@PathVariable("id")Long id){
        serveService.offSale(id);
    }

    // PUT/foundations/operation/serve/Hot/{id}
    @PutMapping("/onHot/{id}")
    @ApiOperation("设置区域服务热门")
    public void onHot(@PathVariable("id")Long id){
        serveService.onHot(id);
    }

    // PUT/foundations/operation/serve/offHot/{id}
    @PutMapping("/offHot/{id}")
    @ApiOperation("取消区域服务热门")
    public void offHot(@PathVariable("id")Long id){
        serveService.offHot(id);
    }
}
